home *** CD-ROM | disk | FTP | other *** search
- /*
- A set of iterators for traversing collections of FSSpecs.
- The basic loop should look like:
- SomeKindOfIter iter ( vol, dir, options );
- iter.Start ();
- while ( iter.More ()) {
- err = iter.Next ( &spec, &bool );
- }
-
- The options that you can pass to the constructor are: (you can mix them, too)
- kNoOptions -- the default, show all files and folders.
- kJustFiles -- skips folders.
- kJustVisible -- skips invisible files and folders
- (Note: Some files/folders are hidden by the finder, and are not
- actually invisible. These include the "Desktop Folder", the Trash folder,
- and the "VM Storage" file.
- kResolveAliases -- if you get a file that is an alias, then resolve it,
- and return what it points to.
-
- Implementation notes:
- If you use kJustFiles or kJustVisible, there will be times that More() will return true,
- and then Next () will return fnfErr. This means that More () saw that there were more files
- in the directory to process, but none of them were files (kJustFiles) or visible (kJustVisible).
- Ignore this error and continue.
- Also, if you specify kResolveAliases, watch for Alias Manager errors when the alias gets resolved.
-
- */
- #ifndef _FILEITERATORS_
- #define _FILEITERATORS_
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- enum {
- kNoOptions = 0,
- kJustFiles = 1,
- kJustVisible = 2,
- kResolveAliases = 4
- };
-
- // Abstract base class for a file iterator
- class TFileIterator {
- protected:
- long fOptions;
- TFileIterator ( long options = kNoOptions );
-
- public:
-
- // Copy from another
- TFileIterator ( TFileIterator &rhs );
-
- virtual ~TFileIterator ();
-
- // Assignment
- TFileIterator& operator= ( TFileIterator& rhs );
-
- virtual void Start ( void ) = 0;
- virtual Boolean More ( void ) = 0;
- virtual OSErr Next ( FSSpec *theSpec, Boolean *isFolder = NULL ) = 0;
- };
-
-
-
- // Walk the files in a single folder
- class TDirectoryIterator : public TFileIterator {
- private:
- TDirectoryIterator (); // Nobody calls this!
-
- protected:
- short fVRefNum; // The volume
- long fParID; // and directory that we are handling
- unsigned long fModDate; // last modification date of this folder
- long fNextIdx; // which item in the directory are we looking at
- long fNumItems; // how many items in the directory
-
- CInfoPBRec fPb; // used to get the info.
-
- void Synchronize ( void ); // detects if the directory has changed, and
- // adjusts the internal counters appropriately.
-
- // Get the next item in the directory
- OSErr GetNextItem ( FSSpec *theSpec, Boolean *isFolder );
-
- public:
-
- // Start from an FSSpec
- TDirectoryIterator ( FSSpec *startPoint, long options = kNoOptions );
-
- // If this is a working directory, resolve it and start there
- // If it is a volume & dirID, start there
- // If it is a volume only, start at the root
- TDirectoryIterator ( short vRefNum, long dirID = fsRtDirID, long options = kNoOptions );
-
- // Copy from another
- TDirectoryIterator ( TFileIterator &rhs );
-
- virtual ~TDirectoryIterator ();
-
- // Assignment
- TDirectoryIterator& operator= ( TDirectoryIterator& rhs );
-
- virtual void Start ( void );
- virtual Boolean More ( void );
- virtual OSErr Next ( FSSpec *theSpec, Boolean *isFolder = NULL );
- };
-
-
- // Walk and recurse
- // Note that using kResolveAliases can lead to
- // a search that never finishes.
- //( _Don't_ try to walk the "Recent Servers" folder, for example. :-)
- class TFileTreeIterator : public TDirectoryIterator {
- protected:
- TDirectoryIterator *fChild;
-
- TFileTreeIterator (); // Nobody calls this!
- public:
- // Start from an FSSpec
- TFileTreeIterator ( FSSpec *startPoint, long options = kNoOptions );
-
- // If this is a working directory, resolve it and start there
- // If it is a volume & dirID, start there
- // If it is a volume only, start at the root
- TFileTreeIterator ( short vRefNum, long dirID = fsRtDirID, long options = kNoOptions );
-
- // Copy from another
- TFileTreeIterator ( TFileTreeIterator &rhs );
-
- virtual ~TFileTreeIterator ();
-
- // Assignment
- TFileTreeIterator& operator= ( TFileTreeIterator& rhs );
-
- virtual void Start ( void );
- virtual Boolean More ( void );
- virtual OSErr Next ( FSSpec *theSpec, Boolean *isFolder = NULL );
- };
-
-
- // Start at a file/folder and proceed up to the root
- class TFilePathIterator : public TFileIterator {
- };
-
-
- // Walk a collection of files ???
- #endif
-